load("@rules_rust//rust:defs.bzl", "rust_doc_test", "rust_library", "rust_test")
load("//bazel:fuzz_testing.bzl", "DEFAULT_RUSTC_FLAGS_FOR_FUZZING")
load("//bazel:prost.bzl", "generated_files_check")

package(default_visibility = ["//visibility:public"])

filegroup(
    name = "protos",
    srcs = glob(["def/**"]),
)

rust_library(
    name = "protobuf",
    srcs = glob([
        "src/**",
    ]),
    crate_name = "ic_protobuf",
    rustc_flags = select({
        "//bazel:fuzzing_code_enabled": DEFAULT_RUSTC_FLAGS_FOR_FUZZING,
        "//conditions:default": [],
    }),
    version = "0.9.0",
    deps = [
        # Keep sorted.
        "//packages/ic-error-types",
        "@crate_index//:bincode",
        "@crate_index//:candid",
        "@crate_index//:erased-serde",
        "@crate_index//:hex",
        "@crate_index//:prost",
        "@crate_index//:serde",
        "@crate_index//:serde_json",
        "@crate_index//:slog",
        "@crate_index//:strum",
    ],
)

rust_test(
    name = "protobuf_test",
    crate = ":protobuf",
    deps = [
        # Keep sorted.
        "@crate_index//:maplit",
    ],
)

rust_doc_test(
    name = "protobuf_doc_test",
    crate = ":protobuf",
)

generated_files_check(
    name = "check_generated_files",
    srcs = ["tests/check_generated_files.rs"],
    data = glob([
        "src/gen/**",
    ]) + [":protos"],
    manifest_dir = "rs/protobuf",
    deps = [
        # Keep sorted.
        "//rs/protobuf/generator:lib",
        "//rs/test_utilities/compare_dirs",
        "@crate_index//:tempfile",
    ],
)
